def __scale_dimensions(width, height, longest_side):
    if width < height:
        return (int(float(longest_side) / height * width), longest_side)
    else:
        return (longest_side, int(float(longest_side) /width * height))

w,h = 100, 200
print __scale_dimensions(w, h, 300)
